﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Data;
using ZHDJ.Data.DataCaching;
using ZHDJ.WebPage.Master;

namespace ZHDJ.Web.PortalParts
{
    public partial class PageMoreGrassroots1 : MorePageMaster
    {
        /// <summary>
        /// 数据访问 
        /// </summary>
        public static AppBoxContext DB
        {
            get
            {
                if (!HttpContext.Current.Items.Contains("__AppBoxContext"))
                {
                    HttpContext.Current.Items["__AppBoxContext"] = new AppBoxContext();
                }
                return HttpContext.Current.Items["__AppBoxContext"] as AppBoxContext;
            }
        }
        /// <summary>
        /// 小组ID
        /// </summary>
        private string ItemID
        {
            get
            {
                return this.Request["ItemID"] ?? "5f6dfbf6ad1d44f2b0dd27a7a4183caa";
            }
        }

        public string ImgUrl { get; set; }
        public string StudioName { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {

            LoadData();

        }

        /// <summary>
        /// 加载
        /// </summary>
        public void LoadData()
        {

            var item = DB.PartyGrassrootsGroupItems.Find(ItemID);
            if (item == null)
            {
                //Response.Redirect("~/default.aspx");
                RedirectToDefault();
            }
            this.litItemName.Text = item.ItemName;


            litLinkAddress.Text = item.LinkAddress;
            litLinkWay.Text = item.LinkMan + "&nbsp;--&nbsp;" + item.LinkMobileNo;
            var moduleQuery = PartyModuleNavigationCaching.Get("PartyGrassrootsItem");
            var m = moduleQuery.FirstOrDefault(a => string.IsNullOrEmpty(a.Category));
            if (m == null)
            {
                //Response.Redirect("~/default.aspx");
                RedirectToDefault();
            }
            ModuleName = m.PageName;
            var q = moduleQuery.Where(a => a.Enabled && !string.IsNullOrEmpty(a.Category));

            rptPage.DataSource = q.ToList();
            rptPage.DataBind();
            hdCategory.Value = Category;
        }

        public string GetUrl(string url)
        {
            var temp = url;
            if (temp.IndexOf('?') > 0)
            {
                temp = temp + "&ItemID=" + this.ItemID;
            }
            else
            {
                temp = temp + "?ItemID=" + this.ItemID;
            }
            return temp;
        }

    }
}